/**
  * @description: json数据压缩为zip压缩包
  * @author: lxz
  * @update: lxz(2021-01-18)
  */
import { saveAs } from 'file-saver'
import JSZip from 'jszip'

export function exportTxtToZip(th, jsonData, txtName = 'file', zipName = 'file') {
  const zip = new JSZip()
  let txtData = `${th}\r\n`
  jsonData.forEach((row) => {
    let tempStr = ''
    tempStr = row.toString()
    txtData += `${tempStr}\r\n`
  })
  zip.file(`${txtName}.txt`, txtData)
  zip.generateAsync({
    type: 'blob'
  }).then((blob) => {
    saveAs(blob, `${zipName}.zip`)
  }, (err) => {
    console.log(err)
    alert('导出失败')
  })
}
